	var visualizationObject;
	function createStatTab() 
	{
		document.getElementById(statisticsTabId).innerHTML ='<div id="loading">' + 
																'<img src="http://www.google.com/ig/images/spinner.gif" />' +
																'<div id="geocoding" style="display:none;">Loading...</div>' +
															'</div><div id = countrydropdown> </div> ' +
															'<table id="geomap_table" cellspacing="0" cellpadding="0" border="0">' +
																'<tr><td>' +
																	'<div id="geomap_container"></div>' +
																'</td></tr>' +
															'</table>' +
															'<script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAjU0EJWnWPMv7oQ-jjS7dYxSPW5CJgpdgO_s4yyMovOaVh_KvvhSfpvagV18eOyDWu7VytS6Bi1CWxw" type="text/javascript"></script>' +
															'<script src="http://www.google.com/jsapi" type="text/javascript"></script>' +
															'<script type="text/javascript">';
	}
	function loadVisCallback() {
		var container = document.getElementById('geomap_container');

		visualizationObject =
		new google.visualization.GeoMap(container);
	}
    function drawStatisticMap() 
	{
		geocoder.getLocations(map.getCenter(), function(addresses) 
		{
			// Show the geocoding message (if exists).
			var geocodingMsgContainer = document.getElementById('geocoding');
			if (geocodingMsgContainer) {
				geocodingMsgContainer.style.display = 'block';
			}
			
			
			
			var address = addresses.Placemark[0];
			var country = address.AddressDetails.Country.CountryNameCode;
			
			sendCountryCode(country);
		});
	}
		
	function sendCountryCode(countryCode) {
		var params = {};
		params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
		var url = GLOBAL_BASE_URL + '/statistics';
		postData = gadgets.io.encodeValues({
				'country' : countryCode
			});
						
		params[gadgets.io.RequestParameters.POST_DATA] = postData;
		gadgets.io.makeRequest(url, drawStatisticMapResponse(countryCode), params);
	}
	
	function updateCountry(select) {
		countryCode = select.options[select.selectedIndex].value;
		sendCountryCode(countryCode);
	}
	
	
	function drawStatisticMapResponse(country)
	{
		return function(response)
		{
			var stat = gadgets.json.parse(response.data);
			var cities = stat.cities;
			var countries = stat.countries;
			
			optionsStr = "";
			for (var i=0; i< countries.length; i++) {
				if (countries[i].code == country) {
					optionsStr += '<OPTION SELECTED VALUE="'+countries[i].code+'">'+countries[i].name+'</OPTION>';
				}
				else {
					optionsStr += '<OPTION VALUE="'+countries[i].code+'">'+countries[i].name+'</OPTION>';
				}
			}
			document.getElementById('countrydropdown').innerHTML = '<select id="selectCountry" onchange="updateCountry(this)">'+ optionsStr + '</select>';
			var data = new google.visualization.DataTable();
			data.addRows(cities.length);
			data.addColumn('string', 'City');
			data.addColumn('number', 'Popularity');
			for(var i=0; i < cities.length; i++)
			{
				data.setValue(i, 0, cities[i].name);
				data.setValue(i, 1, cities[i].counter);
			}
				
			var options = {};
			options['region'] = country;
			options['dataMode'] = 'markers';
			options['height'] = document.body.clientHeight;
			options['width'] = document.body.clientWidth;	
			google.visualization.events.addListener(visualizationObject, 'drawingDone', clearLoadingMessage);
			visualizationObject.draw(data, options);
		};
    };

    function clearLoadingMessage() {
      // Remove the loading message (if exists).
      var loadingMsgContainer = document.getElementById('loading');
      if (loadingMsgContainer) {
        loadingMsgContainer.style.display = 'none';
      }
    };
